#ifndef HASH_FUNCS_H_
#define HASH_FUNCS_H_

#include "CellCoordinates.h"

namespace physicsworks {

class RigidBody;
class WorldModel;

template<class T> struct hash {};

template<> struct hash<RigidBody*>
{
	// TODO: this is not portable, fix it!
	size_t operator () (RigidBody* ptr) const { return reinterpret_cast<size_t>(ptr); }
};

template<> struct hash<const RigidBody*>
{
	// TODO: this is not portable, fix it!
	size_t operator () (const RigidBody* ptr) const { return reinterpret_cast<size_t>(ptr); }
};

template<> struct hash<WorldModel*>
{
	// TODO: this is not portable, fix it!
	size_t operator () (WorldModel* ptr) const { return reinterpret_cast<size_t>(ptr); }
};

template<> struct hash<CellCoordinates>
{
	// function based on an example in the Real-Time Collision Detection book
	// TODO: test it! 
	size_t operator () (const CellCoordinates& c) const {
		const int h1 = 0x8da6b343; // Large multiplicative constants;
		const int h2 = 0xd8163841; // here arbitrarily chosen primes
		const int h3 = 0xcb1ab31f;
		return h1 * c.x + h2 * c.y + h3 * c.z; 
	}
};

}

#endif /*HASH_FUNCS_H_*/
